package com.zsxb.crm.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zsxb.crm.dto.ActivityDto;
import com.zsxb.crm.dto.ActivityPageDto;
import com.zsxb.crm.mapper.ActivityMapper;
import com.zsxb.crm.pojo.Activity;
import com.zsxb.crm.result.PageResult;
import com.zsxb.crm.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
@Slf4j
public class ActivityServiceImpl implements ActivityService {

    @Autowired
    private ActivityMapper activityMapper;
    //活动分页查询
    @Override
    public PageResult pageQuery(ActivityPageDto dto) {
        PageHelper.startPage(dto.getPageNum(),dto.getPageSize());
        Page<Activity> pageVO = activityMapper.pageQuery(dto);
        PageResult pageResult = new PageResult();
        pageResult.setTotal(pageVO.getTotal());
        pageResult.setRows(pageVO.getResult());
        return pageResult;
    }
    //添加活动
    @Override
    public void AddActivity(ActivityPageDto dto) {
        dto.setCreateTime(LocalDateTime.now());
        dto.setUpdateTime(LocalDateTime.now());
        dto.setCreateBy("admin");//后期从session中获取
        activityMapper.insertSelective(dto);
    }
    //删除活动
    @Override
    public void delete(Long id) {
         activityMapper.delete(id);


    }
    //修改活动
    @Override
    public void update(ActivityDto dto) {
//        dto.setUpdateBy("admin");//后期从session中获取
//         dto.setUpdateTime(LocalDateTime.now());
          activityMapper.update(dto);
    }

    @Override
    public Activity getById(Long id) {
        Activity activity =   activityMapper.getById(id);
        return activity;
    }

    @Override
    public List<Activity> getActivityByChannel(Integer channel) {
        return activityMapper.getActivityByChannel(channel);
    }

}
